package com.bwie.bwedu.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.bwie.bwedu.application.App;
import com.bwie.bwedu.asimplecache.ACache;

import org.json.JSONObject;

/**
 * Created by Administrator on 2016/7/22.
 */
public class ASimpleCacheUtils {
    public static final String PREFRECE_NAME="login_info";

    //缓存数据
    public static void write(String name, String value){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
            mACache.put(name, value);
        }
    }

    //读取缓存
    public static String read(String name){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
          String result =  mACache.getAsString(name);
            return  result;
        }
        return  null;
    }

    //清除缓存
    public static void remove(String name){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
            mACache.remove(name);
        }
    }

    //判断是否登陆
    public static boolean readfromExternl(String name){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
            String result =  mACache.getAsString(name);
           if(result!=null){
               return true;
           }
        }
        return  false;
    }

    //缓存JSONObject 数据
    public static void writejsonobject(String name, String value){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
            mACache.put(name, value);
        }
    }

    //读取JSONObject 缓存
    public static JSONObject readjsonobject(String name){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
            JSONObject result =  mACache.getAsJSONObject(name);
            return  result;
        }
        return  null;
    }

    //清除JSONObject 缓存
    public static void removejsonobject(String name){
        ACache mACache = ACache.get(App.getContext());
        if ( mACache!= null && !TextUtils.isEmpty(name)) {
            mACache.remove(name);
        }
    }
}
